<template>
  <div class="app-container">

    <el-card class="box-card" shadow="hover" style="width: 100%" >
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">

      <el-form-item label="手牌号" prop="handBrand">
        <el-input
          v-model="queryParams.handBrand"
          placeholder="请输入手牌号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">查询</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>


    <el-row :gutter="10" class="mb8">
      <!--          <el-col :span="1.5">
                  <el-button
                    type="primary"
                    plain
                    icon="el-icon-plus"
                    size="mini"
                    @click="handleAdd"
                    v-hasPermi="['project:details:add']"
                  >新增</el-button>
                </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
        >修改</el-button>
      </el-col>
      <!--          <el-col :span="1.5">
                  <el-button
                    type="danger"
                    plain
                    icon="el-icon-delete"
                    size="mini"
                    :disabled="multiple"
                    @click="handleDelete"
                    v-hasPermi="['project:details:remove']"
                  >删除</el-button>
                </el-col>-->
      <!--          <el-col :span="1.5">
                  <el-button
                    type="warning"
                    plain
                    icon="el-icon-download"
                    size="mini"
                    @click="handleExport"
                    v-hasPermi="['project:details:export']"
                  >导出</el-button>
                </el-col>-->
      <!--          <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>-->
    </el-row>




    <el-table v-loading="loading" :data="billsList" @selection-change="handleSelectionChange" border >
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="手牌号" align="center" prop="handBrand" />
      <el-table-column label="吧台号" align="center" prop="barNumber" />
      <el-table-column label="同来" align="center" prop="together" />
      <el-table-column label="原手牌" align="center" prop="originalHand" />
      <el-table-column label="手牌类别" align="center" prop="handCategory">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.yqg_hand_category" :value="scope.row.handCategory"/>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="note" />
      <el-table-column label="团体备注" align="center" prop="groupNotes" />
      <!--                    <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                            <template slot-scope="scope">
                              <el-button
                                size="mini"
                                type="text"
                                icon="el-icon-edit"
                                @click="handleUpdate(scope.row)"
                                v-hasPermi="['project:details:edit']"
                              >修改</el-button>
                              <el-button
                                size="mini"
                                type="text"
                                icon="el-icon-delete"
                                @click="handleDelete(scope.row)"
                                v-hasPermi="['project:details:remove']"
                              >删除</el-button>
                            </template>
                          </el-table-column>-->
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改消费详细对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="备注" prop="note">
          <el-input v-model="form.note" type="textarea" placeholder="请输入备注" />
        </el-form-item>
        <el-form-item label="团体备注" prop="groupNotes">

          <el-input v-model="form.groupNotes"  type="textarea" placeholder="请输入团体备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    </el-card> <br>
    <el-button class="right" style="float: right;margin-top: 10px;margin-bottom: 15px" @click="cancel1" >返回</el-button>
    <br>

  </div>
</template>

<script>
  import { listBills, getBills, delBills, addBills, ppp ,ppp1} from "@/api/module/lys/bills";

  export default {
    name: "Details",
    props: ['xiugaihandid'], // 接收传入的 id
    dicts: ['yqg_hand_category', 'yqg_hand_state', 'yqg_payment_method', 'yqg_consumption_status', 'yqg_retention_status', 'yqg_project_category', 'yqg_post', 'yqg_check_out_status', 'yqg_department', 'yqg_merge_status', 'yqg_sailings_signs', 'yqg_next_clock_status'],
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 消费详细表格数据
        billsList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          userId: null,
          deptId: null,
          department: null,
          nickName: null,
          userName: null,
          post: null,
          handBrand: null,
          handCategory: null,
          handState: '1',
          retentionStatus: null,
          mergeStatus: null,
          openingTime: null,
          drawTime: null,
          mergeHands: null,
          mergeBarBillsId: null,
          leaveTime: null,
          beforeLeave: null,
          beforeBarBillsId: null,
          entryName: null,
          projectCategory: null,
          projectCode: null,
          mnemonicCode: null,
          unit: null,
          unitPrice: null,
          commissionPrice: null,
          together: null,
          sailingsSigns: null,
          barBillsId: null,
          recordingTime: null,
          quantity: null,
          totalAmount: null,
          seat: null,
          orderNumber: null,
          paymentMethod: null,
          consumptionStatus: null,
          chargebackTime: null,
          reasonForChargeback: null,
          chargebackProcessorAccount: null,
          chargebackProcessorName: null,
          clockTime: null,
          nextClockTime: null,
          nextClockStatus: null,
          recordEmployeeNumber: null,
          recorderEmployeeName: null,
          roomType: null,
          openingHours: null,
          checkOutTime: null,
          checkOutStatus: null,
          note1: null,
          note2: null,
          note3: null,
          note4: null,
          note5: null,
          note6: null,
          note7: null,
          note8: null,
          note9: null,
          note10: null
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
        }
      };
    },

    watch: {
      xiugaihandid() {
        // 当 id 值发生改变时，重新获取或者刷新数据
        if(this.xiugaihandid){
          this.queryParams.handBrand=this.xiugaihandid[0];
        }
        this.getList();
      },
    },
    created() {
      if(this.xiugaihandid){
        this.queryParams.handBrand=this.xiugaihandid[0];
      }
      this.getList();
    },
    methods: {
      /** 查询消费详细列表 */
      getList() {
        this.loading = true;
        listBills(this.queryParams).then(response => {
          this.billsList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 取消按钮
      cancel1() {
        this.$emit("closeDialog"); // 触发 closeDialog 事件
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          userId: null,
          deptId: null,
          department: null,
          nickName: null,
          userName: null,
          post: null,
          handBrand: null,
          handCategory: null,
          handState: null,
          retentionStatus: null,
          mergeStatus: null,
          openingTime: null,
          drawTime: null,
          mergeHands: null,
          mergeBarBillsId: null,
          leaveTime: null,
          beforeLeave: null,
          beforeBarBillsId: null,
          entryName: null,
          projectCategory: null,
          projectCode: null,
          mnemonicCode: null,
          unit: null,
          unitPrice: null,
          commissionPrice: null,
          together: null,
          sailingsSigns: null,
          barBillsId: null,
          recordingTime: null,
          quantity: null,
          totalAmount: null,
          seat: null,
          orderNumber: null,
          paymentMethod: null,
          consumptionStatus: null,
          chargebackTime: null,
          reasonForChargeback: null,
          chargebackProcessorAccount: null,
          chargebackProcessorName: null,
          clockTime: null,
          nextClockTime: null,
          nextClockStatus: null,
          recordEmployeeNumber: null,
          recorderEmployeeName: null,
          roomType: null,
          openingHours: null,
          checkOutTime: null,
          checkOutStatus: null,
          note1: null,
          note2: null,
          note3: null,
          note4: null,
          note5: null,
          note6: null,
          note7: null,
          note8: null,
          note9: null,
          note10: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length!==1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加消费详细";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const ID = row.id || this.ids
        getBills(ID).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "修改";
        });
      },
      /** 提交按钮 */
      submitForm() {

        ppp1(this.form).then(response => {
          this.$modal.msgSuccess("修改成功");
          this.open = false;
          this.getList();



        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const IDs = row.id || this.ids;
        this.$modal.confirm('是否确认删除消费详细编号为"' + IDs + '"的数据项？').then(function() {
          return delDetails(IDs);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('project/details/export', {
          ...this.queryParams
        }, `details_${new Date().getTime()}.xlsx`)
      }
    }
  };
</script>
